<template>
  <el-form class="form" :model="formData" :rules="rules" label-width="120px">
    <el-form-item :label="'url' + ':'" prop="t1400_url">
      <el-input v-model="formData.t1400_url"></el-input>
    </el-form-item>
    <el-form-item :label="'key' + ':'" prop="t1400_key">
      <el-input v-model="formData.t1400_key"></el-input>
    </el-form-item>
    <el-form-item :label="$t('dataPush.user') + ':'">
      <el-input v-model="formData.user"></el-input>
    </el-form-item>
    <el-form-item :label="$t('dataPush.pwd') + ':'">
      <el-input v-model="formData.pwd" type="text" class="pwd-input"></el-input>
    </el-form-item>
    <el-form-item :label="$t('dataPush.address') + ':'">
      <el-input v-model="formData.address"></el-input>
    </el-form-item>
    <el-form-item :label="$t('dataPush.longitude') + ':'">
      <el-input v-model="formData.longitude"></el-input>
    </el-form-item>
    <el-form-item :label="$t('dataPush.latitude') + ':'">
      <el-input v-model="formData.latitude"></el-input>
    </el-form-item>
    <el-form-item :label="'Service Code' + ':'">
      <el-input v-model="formData.service_code"></el-input>
    </el-form-item>
    <el-form-item :label="'Device Code' + ':'">
      <el-input v-model="formData.device_code"></el-input>
    </el-form-item>
    <el-form-item :label="'Network Code' + ':'">
      <el-input v-model="formData.network_code"></el-input>
    </el-form-item>
    <el-form-item>
      <MyButton class="confirm" @click="handleReset" icon="el-icon-refresh">{{
        $t("dataPush.reset")
      }}</MyButton>
      <MyButton class="confirm" @click="handleConfirm" icon="el-icon-refresh">{{
        $t("common.confirm")
      }}</MyButton>
    </el-form-item>
  </el-form>
</template>

<script>
import { refresh, saveGAT } from "./service";
import util from "@/utils";
export default {
  data() {
    return {
      formData: {},
      rules: {
        t1400_key: [
          {
            required: true,
            message: this.$t("dataPush.keyRequired"),
            trigger: "blur",
          },
        ],
        t1400_url: [
          {
            required: true,
            message: this.$t("dataPush.urlRequired"),
            trigger: "blur",
          },
        ],
      },
    };
  },
  mounted() {
    this.handleReset();
  },
  methods: {
    async handleReset() {
      const res = await refresh();
      if (res.code == 0) {
        this.$set(this, "formData", res.data);
      }
    },
    async handleConfirm() {
      const params = {
        ...this.formData,
      };
      const res = await saveGAT(params);
      if (res.code == 0) {
        util.msg.success("edit_success");
      }
    },
  },
};
</script>

<style lang="less" scoped>
.form {
  /deep/ .el-input {
    width: auto;
  }
  .pwd-input {
    -webkit-text-security: disc;
  }
}
</style>
